import { FormScheme } from '@/pages/form-model/interface';
import { FormFactory } from '@/pages/form-model/model/formFactory';
import { Form } from 'antd';
import SFormItem from './SFormItem';
import React, { useEffect, useImperativeHandle } from 'react';
import { FormModel } from './model/form.model';
import useObservableState from '@/pages/form-model/observeState';
import { useForm } from 'antd/lib/form/Form';
import SFormTest from '@/pages/form-model/SFormTest';

interface SFormProps {
  config: FormScheme;
}

export interface FormRefProps {
  formModel: FormModel;
}

const SForm = React.forwardRef<FormRefProps, SFormProps>((props, ref) => {
  const { config } = props;
  const [form] = useForm();
  const formModel: FormModel = FormFactory.createForm({ form, ...config });

  useImperativeHandle(ref, () => ({
    formModel,
  }));

  return <SFormTest formModel={formModel} />;
});

export default SForm;
